Page({
  data: {
    pic1: '/pages/jsb/image/bu.png',
    pic2: '/pages/jsb/image/wenhao.png',
    pic3: '/pages/jsb/image/jiandao.png',
    pic4: '/pages/jsb/image/shitou.png',
    pic5: '/pages/jsb/image/bu.png',
    num: 0,
    txt1: "猜拳吧",
    arr: [
      "./image/jiandao.png",
      "./image/shitou.png",
      "./image/bu.png"
    ],
    flag: true,
    timer: null
  },
  onLoad() {
    this.start();
  },

  start() {
    let obj = this;
    if (obj.data.flag) {
      obj.data.timer = setInterval(function () {
        let one = Math.floor(Math.random() * 3);
        obj.setData({
          pic1: obj.data.arr[one],
        })
      }, 60)
    }
  },
  btn1() {
    let obj = this;
    clearInterval(obj.data.timer);
    this.setData({
      pic2: obj.data.arr[0],
    })
    if (obj.data.pic1 == obj.data.arr[0]) {
      obj.setData({
        txt1: "平局"
      })
    } else if (obj.data.pic1 == obj.data.arr[1]) {
      obj.setData({
        txt1: '你输了'
      })
    } else {
      obj.setData({
        txt1: '你赢了',
        num:obj.data.num+1
      })
    }
  },
  btn2() {
    let obj = this;
    clearInterval(obj.data.timer);
    this.setData({
      pic2: obj.data.arr[1],
    })
    if (obj.data.pic1 == obj.data.arr[1]) {
      obj.setData({
        txt1: "平局"
      })
    } else if (obj.data.pic1 == obj.data.arr[2]) {
      obj.setData({
        txt1: '你输了'
      })
    } else {
      obj.setData({
        txt1: '你赢了',
        num:obj.data.num+1
      })
    }
  },
  btn3() {
    let obj = this;
    clearInterval(obj.data.timer);
    this.setData({
      pic2: obj.data.arr[2],
    })
    if (obj.data.pic1 == obj.data.arr[2]) {
      obj.setData({
        txt1: "平局"
      })
    } else if (obj.data.pic1 == obj.data.arr[0]) {
      obj.setData({
        txt1: '你输了'
      })
    } else {
      obj.setData({
        txt1: '你赢了',
        num:obj.data.num+1
      })
    }
  },
  click(){
    let obj=this;
    clearInterval(obj.data.timer);
    obj.setData({
      pic2:'/pages/jsb/image/wenhao.png',
      txt1:'猜拳吧'
    })
    this.start()
  },
  methods: {}
})